/**
 * @author 小泽玛丽罗
 * 
 */
// 对Date的扩展，将 Date 转化为指定格式的String 
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function(fmt) 
{ //author: meizz 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  for(var k in o) 
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 
  return fmt; 
};
String.prototype.replaceAll = function (AFindText,ARepText){
	 raRegExp = new RegExp(AFindText,"g");
	 return this.replace(raRegExp,ARepText);};
String.prototype.endWith=function(s){
	if(s==null||s==""||this.length==0||s.length>this.length)
	return false;
	if(this.substring(this.length-s.length)==s)
	return true;
	else
	return false;
	return true;
	};

	String.prototype.startWith=function(s){
	if(s==null||s==""||this.length==0||s.length>this.length)
	return false;
	if(this.substr(0,s.length)==s)
	return true;
	else
	return false;
	return true;
	};
	
var string={
		getString:function(string){
			if(string==undefined){
				return string=" ";
			}else{
				return string;
			}
		},
		dateFormat:function(date,fmt){
		var time=	Date.parse(date);//这里得到的是时间戳，要转换为Date
		var data=new Date(parseInt(time));
		var m=data.getDate()+1;
			var o = { 
				    "M+" : data.getMonth()+1,                 //月份 
				    "d+" : data.getDate(),                    //日 
				    "h+" : data.getHours(),                   //小时 
				    "m+" : data.getMinutes(),                 //分 
				    "s+" : data.getSeconds(),                 //秒 
				    "q+" : Math.floor((data.getMonth()+3)/3), //季度 
				    "S"  : data.getMilliseconds()             //毫秒 
				  }; 
				  if(/(y+)/.test(fmt)) 
				    fmt=fmt.replace(RegExp.$1, (data.getFullYear()+"").substr(4 - RegExp.$1.length)); 
				  for(var k in o) 
				    if(new RegExp("("+ k +")").test(fmt)) 
				  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 
				  return fmt; 
		}
};
var is_commons = 0;
var toast = {
	/**
	 * 成功提示
	 * 
	 * @param text
	 *            内容
	 * @param title
	 *            标题
	 */
	success : function(text, title) {
		toastr.options = {
			"closeButton" : true,
			"debug" : false,
			"positionClass" : "toast-center",
			"onclick" : null,
			"showDuration" : "1000",
			"hideDuration" : "1000",
			"timeOut" : "3000",
			"extendedTimeOut" : "1000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		};
		toastr.success(text, title);
	},
	/**
	 * 失败提示
	 * 
	 * @param text
	 *            内容
	 * @param title
	 *            标题
	 */
	error : function(text, title) {
		toastr.options = {
			"closeButton" : true,
			"debug" : false,
			"positionClass" : "toast-center",
			"onclick" : null,
			"showDuration" : "1000",
			"hideDuration" : "1000",
			"timeOut" : "3000",
			"extendedTimeOut" : "1000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		};
		toastr.error(text, title);
	},
	/**
	 * 信息提示
	 * 
	 * @param text
	 *            内容
	 * @param title
	 *            标题
	 */
	info : function(text, title) {
		toastr.options = {
			"closeButton" : false,
			"debug" : false,
			"positionClass" : "toast-center",
			"onclick" : null,
			"showDuration" : "1000",
			"hideDuration" : "1000",
			"timeOut" : "3000",
			"extendedTimeOut" : "1000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		};
		toastr.info(text, title);
	},
	/**
	 * 警告提示
	 * 
	 * @param text
	 *            内容
	 * @param title
	 *            标题
	 */
	warning : function(text, title) {
		toastr.options = {
			"closeButton" : false,
			"debug" : false,
			"positionClass" : "toast-center",
			"onclick" : null,
			"showDuration" : "1000",
			"hideDuration" : "1000",
			"timeOut" : "3000",
			"extendedTimeOut" : "1000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		};
		toastr.warning(text, title);
	}
};

/**
 * 加载条的选项
 */
var opts = {

        lines: 9, // The number of lines to draw

        length: 0, // The length of each line

        width: 10, // The line thickness

        radius: 15, // The radius of the inner circle

        corners: 1, // Corner roundness (0..1)

        rotate: 0, // The rotation offset

        color: '#000', // #rgb or #rrggbb

        speed: 1, // Rounds per second

        trail: 60, // Afterglow percentage

        shadow: false, // Whether to render a shadow

        hwaccel: false, // Whether to use hardware acceleration

        className: 'spinner', // The CSS class to assign to the spinner

        zIndex: 2e9, // The z-index (defaults to 2000000000)

        top: 'auto', // Top position relative to parent in px

        left: 'auto' // Left position relative to parent in px
    };
var spinner = new Spinner(opts).spin();//进度条
jQuery(function($) {
	var date=new Date();
	for(var i=date.getFullYear();i>=1980;i--){
		$("#nd").append("<option value='"+i+"'>"+i+"</option>"); 
	}
	$(document).ready(function() {
		// enabling stickUp on the '.navbar-wrapper' class
		/*$('.nav_bar').stickUp();*/
		$("#main-container").width(1080);
		$("#main-container").css("margin-bottom", 50);
		//开启前端验证框架
		 //$("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); 
		 var date=new Date();
		 //alert( date.getFullYear());
		 for(var i=1980;i<2020;i++){
			 
		 }
		// $("#nd").append("<option value='Value'>Text</option>"); 
	});
});

/**
 * 绑定点击事件
 */
$(function() {
	getSessionValue("edit");
	/**
	 * 提示框的初始化
	 */
	$("[data-toggle='tooltip']").tooltip({container:true,html:true,selector:"#top"});
	/**
	 * 通用 用以检查表单提交前  input  和select 是否选择有效值
	 */
	$(".validationBeforeSubmit").on('click',function(){
		var $form=$(this).parents("form");
		var inputcount=0;
		var selectcount=0;
		$form.find("input.required").each(function(){
			var value=$(this).val();
			if(value==""||value==null){
				inputcount++;
			}
		});
		$form.find("select.required").each(function(i,element){
			var value=parseInt($(this).val());
			if(value==0){
				selectcount++;
			}
		});
		if(selectcount!=0||inputcount!=0){
			toast.error("请填写和选择必要信息和类型", "温馨提示");
		}else{
			$form.submit();
		}
	});
	
	/**
	 * 分页插件 通用
	 */
	$(".pagePre").on('click' ,function(){
		var $form=$(this).parent();
		var currentPage=$form.find(".currentPage").val()-1;
		$form.find(".currentPage").val(currentPage);
		$form.submit();
	});
	$(".pageNext").on('click' ,function(){
		var $form=$(this).parent();
		var currentPage=parseInt($form.find(".currentPage").val())+1;
		$form.find(".currentPage").val(currentPage);
		$form.submit();
	});
	//顶部菜单栏的事件绑定
	$("li.maintain").hover(function(){
		$(this).find('a:first').addClass("hover");
		var current_li=$(this);
		NavWaitSlide=setTimeout(function(){
			if(!$(current_li).children('ul').is(':visible')){
				$(current_li).find('ul').slideDown(300);
			}
		},100);
	},function(){
		clearTimeout(NavWaitSlide);
		$(this).find('ul').slideUp(300);
		$(this).find('a:first').removeClass("hover");
	});
	// 控制右下返回顶部的按钮显示
	$(window).scroll(function() {
		var top = $(document).scrollTop();
		if (top > 300) {
			$("#goTopBtn").css('display', 'block');
		} else {
			$("#goTopBtn").css('display', 'none');
		}
	});
	$("#goTopBtn").click(function() {
		var sc = $(window).scrollTop();
		$('body,html').animate({
			scrollTop : 0
		}, 500);
	});
	$(".flh").on("click",function(){
		
		var name=$(this).find("#name").text().trim();
		var xh=$(this).find("#xh").text().trim();
		var flh=$(this).find("#flh").text().trim();
		$modal=$("#flhModal");
		$modal.find("#flhXh").val(xh);
		$modal.find("#flh").val(flh);
		$modal.find("#flhName").val(name);
		$modal.modal('show');
		
	});
	$(".flhSub").on("click",function(){
		var flh=$(this).find("input").val();
		var name=$(this).find("td:first").text().trim();
		var code=$(this).find("td:first").next().text();
		
	});
	$("#btnSearch").on("click",function(event){
		event.stopPropagation();
		var bt=$("#bt").val().trim();
		var swbh=$("#swbh").val().trim();
		var nd=$("#nd").val().trim();
		var sw=$("#sw").val().trim();
		//显示进度条
		showLoader();
		$.ajax({
			url:"/dangan/webService/show/oawj/searchOaWj",
			type:"post",
			data:{'swbh':swbh,nd:nd,bt:bt,sw:sw},
			success:function(data){
				console.info(data);
				var vrecid=1;
				$(data).each(function(index,ele){
					//该文档在OA中的唯一id，用来在档案库中搜索该文档是否归档
					hideLoader();
					window.localStorage.setItem("guidang", JSON.stringify(ele));
					//只显示搜索的第一个
					if(index==0){
						$("#yxlj").val(ele["lj"]);
						$("#nd").val(ele["nd"]);
						$("#bt").val(ele["vlwbt"]);
						$("#zrr").val(ele["vlwdw"]);
						$("#sw").val(ele["vlwbh"]);
						$("#data").val(ele["vlastdate"]);
						$("#swbh").val(ele["vswbh"]);
						if(parseInt(ele["stats"])==0){
							$("#stats").text("未归档");
						}else {
							$("#stats").text("已归档");
						}
						vrecid=ele["vrecid"];
					}
				});
				//更新默认的该年度,该分类号，保管期限的件数
				var nd=$("#nd").val();
				var flh=$("#flh").val();
				var bgqx=$("#bgqx").val();
				$.ajax({
					url:"/dangan/webService/show/DaQyajb/countWj",
					type:"post",
					data:{nd:nd,flh:flh,bgqx:bgqx},
					success:function(data){
						hideLoader();
						$("#jh").val(data["count"]);
					},
					error:function(data){
						
					}
				});
				//判断搜索到的文档的归档状态
				$.ajax({
					url:"/dangan/webService/show/DaQyajb/isGuidang",
					type:"post",
					data:{recid:vrecid},
					success:function(data){
						if(data["success"]){
							$("#status").val(1);
							$("#stats").text("已归档");
						}else{
							$("#status").val(0);
							$("#stats").text("未归档");
						};
					},
					error:function(data){
						
					}
				});
				
			},
			error:function(data){
			}
		});
	});
	$(".nav-select ul li").on("click",function(){
		var selectedFlh=$(this).attr("id");
		$(".nav-select ul li").removeClass('active');
		$(this).addClass('active');
		$("#flh").val(selectedFlh);
	});
	 $(".nav-select ul a").on("click",function(){
			var flh=$(this).attr("id");
			switch (flh) {
			case "A":
				window.location="/dangan/querySub.action?to=zhl";
				break;
			case "B":
				window.location="/dangan/querySub.action?to=jhcwl";
				break;
			case "C":
				window.location="/dangan/querySub.action?to=djgll";
				break;
			case "D":
				window.location="/dangan/querySub.action?to=djgll";
				break;
			case "E":
				window.location="/dangan/querySub.action?to=djgll";
				break;
			case "F":
				window.location="/dangan/querySub.action?to=djgll";
				break;
			case "G":
				window.location="/dangan/querySub.action?to=jsydlml";
				break;
			case "I":
				window.location="/dangan/querySub.action?to=djgll";
				break;
			case "Y":
				window.location="/dangan/querySub.action?to=tdzll";
				break;
			case "Z":
				window.location="/dangan/querySub.action?to=dylda";
				break;
			default:
				break;
			}
	});
	$("#bgqx").change(function(){
		var nd=$("#nd").val();
		var flh=$("#flh").val();
		var bgqx=$("#bgqx").val();
		if(isNumber(nd)){
			toast.error("请在年度栏填写正确的年度", "温馨提示");
			return false;
		}
		showLoader();
		$.ajax({
			url:"/dangan/webService/show/DaQyajb/countWj",
			type:"post",
			data:{nd:nd,flh:flh,bgqx:bgqx},
			success:function(data){
				hideLoader();
				$("#jh").val(data["count"]);
			},
			error:function(data){
				
			}
			
		});
		
		
	});
	
	
	$("#btn_search").on("click",function(){
		var jh=$("#jh").val();
		var nd=$("#nd").val();
		var bgqx=$("#qbgqx").val();
		var wh=$("#wh").val();
		var bt=$("#bt").val();
		var newflh=parent.getFlh();
		if(isNaN(parseFloat(jh))){
			jh=0;
		}
		var everyPage=$("#everyPage").val();
		if(isNaN(parseInt(everyPage))){
			toast.error("页数必须为大于0的整数", "温馨提示");
			return ;
		}
		$("#anjuanTable tbody tr").remove();
		showLoader();
		/*var flh=$(".list-group-item.active").attr('id');*/
		$.ajax({
			url:"/dangan/webService/show/DaQyajb/query",
			type:"post",
			data:{js:jh,nd:nd,bgqx:bgqx,wh:wh,bt:bt,newflh:newflh,orderBy:"js",everyPage:everyPage},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				if(data["success"]){
					hideLoader();
					//行数=（当前页-1）*每页记录数
					var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
					$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
					$(data["result"]).each(function(index,ele){
						var hh=num+parseInt(index)+1;
						var c=index%2;
						var background="";
						if(c==0){
							background="style='background:#D9DEE4'";
						}else{
							background="style=''";
						}
						var btn_edit="";
						var editable=window.sessionStorage.getItem("edit");
						if(editable=="true"){
							btn_edit="<button  class='btn btn-link btn_edit' value='"+ele["nbxh"]+"'>编辑</button>";
						}
						if(ele["status"]=='0'){
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"'"+ background+" data-toggle='tooltip' data-selector='#top'  class='hand anjuan' >"+
									"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["bt"]+"</td>"+
									"<td>"+ele["bgqx"]+"</td>"+
									"<td class='tdStyle'>"+string.getString(ele["wh"])+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+string.getString(ele["js"])+"</td>"+
									"<td>"+"<button value="+ele["status"]+" class='btn btn-primary lendbtn'>借阅</button><button id='"+ele["nbxh"]+"' name='0' value='seePdf.action?nbxh="+ele["nbxh"]+"&jnmlbh=1&inmlbh=1&gcwz=0' class='btn btn-default ml_5 lookbtn'>查看</button>"+btn_edit+"</td>"+
									"</tr>");
						}else{
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"'"+background+" data-toggle='tooltip' data-selector='#top'  class='hand anjuan' >  "+
									"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["bt"]+"</td>"+
									"<td>"+ele["bgqx"]+"</td>"+
									"<td class='tdStyle'>"+string.getString(ele["wh"])+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+string.getString(ele["js"])+"</td>"+
									"<td>"+"<button value="+ele["status"]+" class='btn btn-danger lendbtn' >借出</button> <button id='"+ele["nbxh"]+"' name='0' value='seePdf.action?nbxh="+ele["nbxh"]+"&jnmlbh=1&inmlbh=1&gcwz=0' class='btn btn-default ml_5 lookbtn'>查看</button>"+btn_edit+"</td>"+
									"</tr>");
						}
					});
				}else{
					toast.error(data["message"], "温馨提示");
				}
			},
			error:function(data){
				toast.error("请求错误", "温馨提示");
			}
		});		
	});
	$("#btn_search_bj").on("click",function(){
		var jh=$("#jh").val();
		var nd=$("#nd").val();
		var bgqx=$("#qbgqx").val();
		var wh=$("#wh").val();
		var bt=$("#bt").val();
		var newflh=parent.getFlh();
		if(isNaN(parseFloat(jh))){
			jh=0;
		}
		var everyPage=$("#everyPage").val();
		if(isNaN(parseInt(everyPage))){
			toast.error("页数必须为大于0的整数", "温馨提示");
			return ;
		}
		$("#anjuanTable tbody tr").remove();
		$("#afterTable tbody tr").remove();
		showLoader();
		/*var flh=$(".list-group-item.active").attr('id');*/
		$.ajax({
			url:"/dangan/webService/show/DaQyajb/query",
			type:"post",
			data:{js:jh,nd:nd,bgqx:bgqx,wh:wh,bt:bt,newflh:newflh,orderBy:"js",everyPage:everyPage},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				if(data["success"]){
					hideLoader();
					//行数=（当前页-1）*每页记录数
					var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
					$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
					$(data["result"]).each(function(index,ele){
						var hh=num+parseInt(index)+1;
						var c=index%2;
						var background="";
						if(c==0){
							background="style='background:#D9DEE4'";
						}else{
							background="style=''";
						}
						var btn_edit="";
						var editable=window.sessionStorage.getItem("edit");
						if(editable=="true"){
							btn_edit="<button  class='btn btn-link btn_edit' value='seePdf.action?nbxh="+ele["nbxh"]+"&jnmlbh=1&inmlbh=1&gcwz=0' id='"+ele["nbxh"]+"'>编辑</button>";
						}
						if(ele["status"]=='0'){
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"'"+ background+" data-toggle='tooltip' data-selector='#top'  class='hand anjuan' >"+
									"<td><input type=\"checkbox\" id='"+ele["nbxh"]+"' name='del_cbx' class='del_radio'></td>"+
									"<td><input type=\"checkbox\" id='"+ele["nbxh"]+"' name='print_cbx' class='print_radio'></td>"+
									"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["bt"]+"</td>"+
									"<td>"+ele["bgqx"]+"</td>"+
									"<td class='tdStyle'>"+string.getString(ele["wh"])+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+string.getString(ele["js"])+"</td>"+
									"<td>"+btn_edit+"</td>"+
									"</tr>");
						}else{
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"'"+background+" data-toggle='tooltip' data-selector='#top'  class='hand anjuan' >  "+
									"<td><input type=\"checkbox\" id='"+ele["nbxh"]+"' name='del_cbx' class='del_radio'></td>"+
									"<td><input type=\"checkbox\" id='"+ele["nbxh"]+"' name='print_cbx' class='print_radio'></td>"+
									"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["bt"]+"</td>"+
									"<td>"+ele["bgqx"]+"</td>"+
									"<td class='tdStyle'>"+string.getString(ele["wh"])+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+string.getString(ele["js"])+"</td>"+
									"<td>"+btn_edit+"</td>"+
									"</tr>");
						}
						$("#afterTable").append("<tr hidden='hidden' id='"+ele["nbxh"]+"'"+background+" data-toggle='tooltip' data-selector='#top'  class='hand anjuan' >  "+
								"<td class='text-canter'>"+string.getString(ele["js"])+"</td>"+
								"<td >"+ele["zrr"]+"</td>"+
								"<td>"+string.getString(ele["wh"])+"</td>"+
								"<td >"+ele["bt"]+"</td>"+
								"<td>"+ele["nd"]+"</td>"+
								"<td>"+ele["bgqx"]+"</td>"+
								"</tr>");
						
					});
				}else{
					toast.error(data["message"], "温馨提示");
				}
			},
			error:function(data){
				toast.error("请求错误", "温馨提示");
			}
		});		
	});
	$("#btn_search_jsydlml").on("click",function(){
		var nd=$("#nd").val();
		var ajh=$("#ajh").val();
		var tdzl=$("#tdzl").val();
		var pzwh=$("#pzwh").val();
		var yddw=$("#yddw").val();
		$("#anjuanTable tbody tr").remove();
		showLoader();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/jsyd/jsydQuery",
			data:{yddw:yddw,nd:nd,ajh:ajh,tdzl:tdzl,pzwh:pzwh},
			success:function(data){
				console.info(data);
				window.localStorage.setItem("page",JSON.stringify(data));
				window.localStorage.setItem("url","/dangan/webService/show/jsyd/jsydQuery");
				var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
				$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
				//$("#anjuanTable tr").remove();
				hideLoader();
				$(data["result"]).each(function(index,ele){
					var hh=num+parseInt(index)+1;
					$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"'  class='hand ' >"+"<td>"+hh+"</td>"
							+"<td>"+ele["ajh"]+"</td>"
							+"<td>"+ele["nd"]+"</td>"+
							"<td>"+ele["pzmj"]+"</td>"+
							"<td>"+ele["pzwh"]+"</td>"+
							"<td>"+ele["tdzl"]+"</td>"+
							"</tr>");
				});
			},
			error:function(data){
				
			}
		});
	});
	/**
	 * 市局和江北的地籍类档案结合后的视图的搜索
	 */
	$("#btn_search_DaQyajb_sj_jb").on("click",function(){
		var landUser=$("#landUser").val();
		var zh=$("#zh").val();
		var position=$("#position").val();
		var th=$("#th").val();
		var dh=$("#dh").val();
		var ajh=$("#ajh").val();
		var flh=parent.getFlh();
		var subFlh=$("#subFlh").val();
		var newflh=parent.getFlh();
		/*var flh=$(".list-group-item.active").attr('id');*/
		$("#anjuanTable tbody tr").remove();
		showLoader();
		var gcwz=$("#gcwz").val();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DaDjgl/query",
			data:{everyPage:13,onwer:landUser,zh:zh,th:th,dh:dh,position:position,ajh:ajh,gcwz:gcwz,flh:subFlh},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				//$("#anjuanTable tbody tr").remove();
				hideLoader();
				if(data["success"]){
					//行数=（当前页-1）*每页记录数
					var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
					$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
					$(data["result"]).each(function(index,ele){
						var hh=num+parseInt(index)+1;
						var btn='';
						if(ele["status"]=='0'){//没有借出
							if(ele["gcwz"]=='1'){
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"' value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
							}else{
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button><button value="+ele["status"]+" class='btn btn-primary lendbtn' >借阅</button>"+"</td>";
							}
						}else{ 
							if(ele["gcwz"]=='1'){
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
							}else{
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button><button value="+ele["status"]+" class='btn btn-danger lendbtn' >借出</button>"+"</td>";
							}
						}
						var c=index%2;
						var background="";
						if(c==0){
							background="style='background:#D9DEE4;'";
						}else{
							background="style=''";
						}
						var location="";
						switch (ele["gcwz"]) {
						case "0":
							location="市局";
							break;
						case "1":
							location="江北";
							break;
						default:
							break;
						}
						if(flh=="E"){
							
							$("#anjuanTable").append("<tr id='"+ele["id"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"
									+"<td class=''>"+ele["zh"]+"</td>"+
									"<td class=''>"+ele["onwer"]+"</td>"+
									"<td class=''> "+ele["position"]+"</td>"+
									"<td>"+ele["ajh"]+"</td>"+
									"<td>"+string.getString(ele["nd"])+"</td>"+
									"<td>"+location+"</td>"+
									btn+
									"</tr>");
						}else{
							$("#anjuanTable").append("<tr id='"+ele["id"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"
									+"<td class=''>"+ele["zh"]+"</td>"+
									"<td class=''>"+ele["onwer"]+"</td>"+
									"<td class=''>"+ele["position"]+"</td>"+
									"<td>"+ele["ajh"]+"</td>"+
									"<td>"+string.getString(ele["nd"])+"</td>"+
									"<td>"+location+"</td>"+
									btn+
									"</tr>");
						}
					});
				}else{
					toast.error(data["message"], "温馨提示");
				}
			},
			
			error:function(data){
				
			}
			
		});
	});
	/**
	 * 市局和江北的建设用类档案结合后的视图的搜索
	 */
	$("#btn_search_Jsydl_sj_jb").on("click",function(){
		var landUser=$("#landUser").val();
		var pzwh=$("#zh").val();
		var position=$("#position").val();
		//var th=$("#th").val();
		var dh=$("#dh").val();
		var ajh=$("#ajh").val();
		var flh=parent.getFlh();
		var subflh=$("#subFlh").val();
		var newflh=parent.getFlh();
		var gcwz=$("#gcwz").val();
		var bt=$("#bt").val().trim();//项目名称
		/*var flh=$(".list-group-item.active").attr('id');*/
		$("#anjuanTable tbody tr").remove();
		showLoader();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/daJsydl/query",
			data:{landuser:landUser,position:position,ajh:ajh,gcwz:gcwz,flh:subflh,bt:bt,pzwh:pzwh},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				//$("#anjuanTable tbody tr").remove();
				hideLoader();
				if(data["success"]){
					//行数=（当前页-1）*每页记录数
					var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
					$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
					$(data["result"]).each(function(index,ele){
						var hh=num+parseInt(index)+1;
						var btn='';
						if(ele["status"]=='0'){//没有借出
							if(ele["gcwz"]=='1'){
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
							}else{
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button><button value="+ele["status"]+" class='btn btn-primary lendbtn' >借阅</button>"+"</td>";
							}
						}else{ 
							if(ele["gcwz"]=='1'){
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
							}else{
								btn="<td>"+"<button id='"+ele["id"]+"' name='"+ele["gcwz"]+"'  value='seePdf.action?nbxh="+ele["id"]+"&jnmlbh=1&inmlbh=1&gcwz="+ele["gcwz"]+"' class='btn btn-default ml_5 lookbtn'>查看</button><button value="+ele["status"]+" class='btn btn-danger lendbtn' >借出</button>"+"</td>";
							}
						}
						var c=index%2;
						var background="";
						if(c==0){
							background="style='background:#D9DEE4;'";
						}else{
							background="style=''";
						}
						var location="";
						switch (ele["gcwz"]) {
						case "0":
							location="市局";
							break;
						case "1":
							location="江北";
							break;
						default:
							break;
						}
						if(flh=="E"){
							$("#anjuanTable").append("<tr id='"+ele["id"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"+
									"<td class=''>"+string.getString(ele["pzwh"])+"</td>"+
									"<td class=''>"+ele["landuser"]+"</td>"+
									"<td class=''>"+string.getString(ele["position"])+"</td>"+
									"<td> "+string.getString(ele["bt"])+"</td>"+
									"<td class=''> "+ ele["ajh"]+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+location+"</td>"+
									btn+
									"</tr>");
						}else{
							$("#anjuanTable").append("<tr id='"+ele["id"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"
									+"<td class=''>"+ele["zh"]+"</td>"+
									"<td class=''>"+ele["onwer"]+"</td>"+
									"<td class=''>"+string.getString(ele["position"])+"</td>"+
									"<td> "+string.getString(ele["bt"])+"</td>"+
									"<td>"+ele["ajh"]+"</td>"+
									"<td>"+ele["nd"]+"</td>"+
									"<td>"+location+"</td>"+
									btn+
									"</tr>");
						}
					});
				}else{
					toast.error(data["message"], "温馨提示");
				}
			},
			error:function(data){
				
			}
			
		});
	});
	$("#btn_search_DaQyajb").on("click",function(){
		var landUser=$("#landUser").val();
		var zh=$("#zh").val();
		var position=$("#position").val();
		var th=$("#th").val();
		var dh=$("#dh").val();
		var pzwh=$("#pzwh").val();
		var ajh=$("#pzwh").val();
		var flh=parent.getFlh();
		var newflh=parent.getFlh();
		/*var flh=$(".list-group-item.active").attr('id');*/
		$("#anjuanTable tbody tr").remove();
		showLoader();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DaQyajb/query",
			data:{landuser:landUser,zh:zh,position:position,th:th,dh:dh,pzwh:pzwh,ajh:ajh,newflh:newflh},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				//$("#anjuanTable tbody tr").remove();
				hideLoader();
				if(data["success"]){
					//行数=（当前页-1）*每页记录数
					var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
					$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
					$(data["result"]).each(function(index,ele){
						var hh=num+parseInt(index)+1;
						var btn='';
						if(ele["status"]=='0'){//没有借出
							btn="<td>"+"<button value="+ele["status"]+" class='btn btn-primary lendbtn' >借阅</button><button id='"+ele["nbxh"]+"' value='seePdf.action?nbxh="+ele["nbxh"]+"&jnmlbh=1&inmlbh=1' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
						}else{ 
							btn="<td>"+"<button value="+ele["status"]+" class='btn btn-danger lendbtn' >借出</button><button id='"+ele["nbxh"]+"' value='seePdf.action?nbxh="+ele["nbxh"]+"&jnmlbh=1&inmlbh=1' class='btn btn-default ml_5 lookbtn'>查看</button>"+"</td>";
						}
						var c=index%2;
						var background="";
						if(c==0){
							background="style='background:#D9DEE4;'";
						}else{
							background="style=''";
						}
						if(flh=="E"){
							
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["pzwh"]+"</td>"+
									"<td class='tdStyle'>"+ele["landuser"]+"</td>"+
									"<td class='tdStyle'> "+ele["position"]+"</td>"+
									"<td>"+ele["ajh"]+"</td>"+
									btn+
									"</tr>");
						}else{
							$("#anjuanTable").append("<tr id='"+ele["nbxh"]+"' "+background+"  class='' >"+"<td>"+hh+"</td>"
									+"<td class='tdStyle'>"+ele["zh"]+"</td>"+
									"<td class='tdStyle'>"+ele["landuser"]+"</td>"+
									"<td class='tdStyle'>"+ele["position"]+"</td>"+
									"<td>"+ele["ajh"]+"</td>"+
									btn+
									"</tr>");
						}
					});
				}else{
					toast.error(data["message"], "温馨提示");
				}
			},
			error:function(data){
				
			}
			
		});
	});
	$("#btn_search_tdzll").on("click",function(){
		var xmmc=$("#xmmc").val().trim();
		var qh=$("#qh").val().trim();
		var ajh=$("#ajh").val().trim();
		var zpzwh=$("#zpzwh").val();
		var zlxwh=$("#zlxwh").val();
		var ylxwh=$("#ylxwh").val();
		var nd =$("#nd").val();
		$("#anjuanTable tbody tr").remove();
		showLoader();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Tdzlda/query",
			data:{xmmc:xmmc,qh:qh,zpzwh:zpzwh,zlxwh:zlxwh,ylxwh:ylxwh,nd:nd,ajh:ajh,newflh:newflh},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				//行数=（当前页-1）*每页记录数
				var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
				$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
				hideLoader();
				//$("#anjuanTable tr").remove();
				$(data["result"]).each(function(index,ele){
					var hh=num+parseInt(index)+1;
					
						$("#anjuanTable").append("<tr id="+ele["nbxh"]+"  class='' >"+"<td>"+hh+"</td>"
								+"<td>"+ele["xmmc"]+"</td>"+
								"<td>"+ele["qh"]+"</td>"+
								"<td>"+ele["zpzwh"]+"</td>"+
								"<td>"+ele["zlxwh"]+"</td>"+
								"<td>"+ele["ylxwh"]+"</td>"+
								"<td>"+ele["nd"]+"</td>"+
								"<td>"+ele["ajh"]+"</td>"+
								"</tr>");
					
				});
			},
			error:function(data){
				
			}
		});
		
	});
	$("#btn_search_dylda").on("click",function(){
		var landuser=$("#landuser").val();
		var ajh=$("#ajh").val();
		var qzh=$("#qzh").val();
		var nd=$("#nd").val();
		$("#anjuanTable tbody tr").remove();
		showLoader();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Dylda/query",
			data:{qzh:qzh,landuser:landuser,nd:nd,ajh:ajh},
			success:function(data){
				window.localStorage.setItem("page",JSON.stringify(data));
				//行数=（当前页-1）*每页记录数
				var num=(parseInt(data["currentPage"])-1)*parseInt(data["everyPage"]);
				$("#totalCount").text("总共"+data["totalCount"]+"条  | 共 " +data["totalPage"]+" 页  / 第   "+data["currentPage"]+" 页");
				hideLoader();
				//$("#anjuanTable tr").remove();
				$(data["result"]).each(function(index,ele){
					var hh=num+parseInt(index)+1;
					
						$("#anjuanTable").append("<tr  id="+ele["nbxh"]+"  class='' >"+"<td>"+hh+"</td>"
								+"<td>"+ele["qzh"]+"</td>"+
								"<td>"+ele["landuser"]+"</td>"+
								"<td>"+ele["nd"]+"</td>"+
								"<td>"+ele["ys"]+"</td>"+
								"<td>"+ele["jzsj"]+"</td>"+
								"<td>"+ele["ajh"]+"</td>"+
								"</tr>");
					
				});
			},
			error:function(data){
				
			}
		});
		
	});
	//监听案卷的借阅事件
	$("#anjuanTable").on("click",".lendbtn",function(){
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/tchuman/getHumanById",
			data:{humanId:307},
			success:function(data){
				$(data).each(function(index,ele){
					$("#jyr").val(ele["humanName"]);
					$("#lxdh").val(ele["telMobile"]);
				});
				
			},
			error:function(data){
				toast.error("请求错误，请稍后再试", "温馨提示");
			}
		});
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/tcunit/getUnitByHumanId",
			data:{humanId:307},
			success:function(data){
				$(data).each(function(index,ele){
					$("#dwbm").val(ele["unitName"]);
				});
				
			},
			error:function(data){
				toast.error("请求错误，请稍后再试", "温馨提示");
			}
		});
		if($(this).val()==1){
			toast.error("该文档已经借出", "温馨提示");
		}else{
			var nbxh=$(this).parent().parent().attr("id");
			var data=window.localStorage.getItem("page");
			var jsonObject =JSON.parse(data);
			$(jsonObject["result"]).each(function(index,ele){
				if(ele["nbxh"]==nbxh){
					var bt=string.getString(ele["bt"]);
					$("#wjbt").val(string.getString(ele["bt"])+string.getString(ele["zh"]));
					$("#wjnbxh").val(nbxh);
				}
			});
			document.getElementById('jyrq').valueAsDate = new Date();
			$("#jyModal").modal('show');
		}
		return false;
	});
	$("#applyJyjl").on("click",function(){
		var lxdh=$("#lxdh").val().trim();
		var dwbm=$("#dwbm").val().trim();
		var jyqx=$("#ghrq").val();
		var jyrq=$("#jyrq").val();
		var jyr=$("#jyr").val();
		var bt=$("#wjbt").val().trim();
		var nbxh=$("#wjnbxh").val();
		if(jyqx==null||jyqx==""){
			toast.error("请选择归还时间", "温馨提示");
			return false;
		}
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Jyjl/createJyjl",
			data:{jyhumanid:678,lxdh:lxdh,jyr:jyr,jyrq:jyrq,jyqx:jyqx,dwbm:dwbm,bt:bt,nbxh:nbxh},
			success:function(data){
				if(data["success"]){
					$(data).each(function(index,ele){
						$("#dwbm").val(ele["unitName"]);
					});
					toast.success("申请成功，等待审批", "温馨提示");
				}else{
					toast.error("对不起，案卷已经外界，由于缓存，状态未及时更新", "温馨提示");
				}
			},
			error:function(data){
				toast.error("请求错误，请稍后再试", "温馨提示");
			}
		});
	});
	
	
	/**
	 * 对于动态增加的节点要先找到他们的父节点，然后再监听父节点下的子节点
	 */
	/*$("#anjuanTable").on("click","tr",function(){
		var nbxh=$(this).attr("id");
		$("#jnmlModal tbody tr").remove();
		$("#jnmlModal").modal('show');
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/filePath/getJnml",
			data:{nbxh:nbxh},
			success:function(data){
				var jsonArray=eval(data);
				for(var i=0;i<jsonArray.length;i++){
					$(".jnml tbody").append("<tr  class=' '>"+
							"<td>"+jsonArray[i].mlclh+"</td>"+
							"<td>"+jsonArray[i].clmlmc+"</td>"+
							"<td>"+jsonArray[i].inmlqx+"  </td>"+
							"<td> <input id=jnmlbh value="+jsonArray[i].id.jnmlbh+" type='hidden'  >" +
							"<input id=inmlbh value="+jsonArray[i].id.inmlbh+" type='hidden'  >" +
							"<button  id="+jsonArray[i].id.nbxh+" class='btn btn-default seepdf '" +
							" value=seePdf.action?nbxh="+jsonArray[i].id.nbxh+
							"&jnmlbh="+jsonArray[i].id.jnmlbh+"&inmlbh="+jsonArray[i].id.inmlbh+"&wjqxCode="+jsonArray[i].inmlqx+
							" >查看</button></td>"+
						"</tr>");
				}
				
			},
			error:function(data){
				toast.error("请求错误，请稍后再试", "温馨提示");
			}
		});
	});*/
	//监听查看pdf的按钮
	/**
	 * 
	 */
	$("#jnmlModal").on("click",".seepdf",function(){
		var height=$(window).height();
		var width=$(window).width();
		var pdf=$("#pfdModal");
		var url=$(this).val();
		$("#pdfIframe").attr('src',url);
		$("#jnmlModal").modal('hide');
		pdf.find(".modal-body").css({
			height:height-120
		});
		pdf.find(".modal-dialog").css({
			width:width,
			height:height,
			margin:0
		});
		pdf.modal('show').css({
			 width: width,
             height:height
		});
		
	});
	//替换上面的对模态窗里面seepdf按钮的监听
	$("#anjuanTable").on("click",".lookbtn",function(event){
		event.stopPropagation();
		var height=$(window).height();
		var width=$(window).width();
		var pdf=$("#pfdModal");
		var flh=parent.getFlh();
		var url=$(this).val()+"&daFlh="+flh;
		window.localStorage.setItem("printFlh",flh);
		var gcwz=$(this).attr("name");
		//这个用来告诉等会要打印的文件的馆藏位置在哪里，来区分确定获取pdfurl的方法
		window.localStorage.setItem("gcwz", gcwz);
		$("#pdfIframe").attr('src',url);
		//$("#jnmlModal").modal('hide');
		pdf.find(".modal-body").css({
			height:height-55
		});
		pdf.find(".modal-dialog").css({
			width:width,
			height:height,
			margin:0
		});
		pdf.modal('show').css({
			 width: width,
             height:height
		});
	});
	$("#testRestful").on("click",function(){
		var val=$(window.parent.document).find("#container2 .active").attr('id');
		alert(val);
		parent.getFlh();
		/*var map=new Map();
		map.param1="1";
		var map1="user=sas&name=sdad";
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/jsyd/jsydQuery",
			data:{nd:"2010"},
			success:function(data){
				console.info(data);
			},
			error:function(data){
			}
		});*/
	});
	//借阅审批
	$(".jysp").on("click",function(){
		var nbxh =$(this).attr("id");
		$("#spModal").modal('show');
		var jyid=$(this).find(".jy").attr('id');
		window.localStorage.setItem("nbxh", nbxh);
		window.localStorage.setItem("jyid","#"+jyid);
		$("#tysp").val(jyid);
		$("#btysp").val(jyid);
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DaQyajb/findDa",
			data:{nbxh:nbxh},
			success:function(data){
				console.info(data[0]);
				$("#wjbt").val(string.getString(data[0]["bt"])+string.getString(data[0]["zh"]));
				$("#wh").val(data[0]["wh"]);
				$("#nd").val(data[0]["nd"]+string.dateFormat(data[0]["rq"], "yyyy"));
				$("#bgqx").val(data[0]["bgqx"]);
				$("#jh").val(data[0]["js"]);
			},
			error:function(data){
				
			}
		});
	});
	$("#jyspf").on("click","tr",function(){
		var nbxh =$(this).attr("id");
		$("#spModal").modal('show');
		var jyid=$(this).find(".jy").attr('id');
		window.localStorage.setItem("nbxh", nbxh);
		window.localStorage.setItem("jyid","#"+jyid);
		$("#tysp").val(jyid);
		$("#btysp").val(jyid);
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DaQyajb/findDa",
			data:{nbxh:nbxh},
			success:function(data){
				console.info(data[0]);
				$("#wjbt").val(string.getString(data[0]["bt"])+string.getString(data[0]["zh"]));
				$("#wh").val(data[0]["wh"]);
				$("#nd").val(data[0]["nd"]+string.dateFormat(data[0]["rq"], "yyyy"));
				$("#bgqx").val(data[0]["bgqx"]);
				$("#jh").val(data[0]["js"]);
			},
			error:function(data){
				
			}
		});
	});
	$("#tysp").on("click",function(){
		var jyid=$(this).val();
		var nbxh=window.localStorage.getItem("nbxh");
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Jyjl/sp",
			data:{jyid:jyid,ty:"1",nbxh:nbxh,status:1},
			success:function(data){
				if(data["result"]){
					toast.success("审批成功", "温馨提示");
				}else {
					toast.error(data["message"]+"该条记录已被置为不通过审批", "温馨提示");
				}
				$(window.localStorage.getItem("jyid")).parent().remove();
			},
			error:function(data){
				
			}
		});
	});
	$("#btysp").on("click",function(){
		var jyid=$(this).val();
		var nbxh=window.localStorage.getItem("nbxh");
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Jyjl/sp",
			data:{jyid:jyid,ty:"2",nbxh:nbxh,status:0},
			success:function(data){
				if(data["result"]){
					toast.error("审批不通过", "温馨提示");
					$(window.localStorage.getItem("jyid")).parent().remove();
				}
			},
			error:function(data){
				
			}
		});
	});
	$(".jygh").on("click",function(){
		var click=true;
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Jyjl/query",
			data:{status:1},
			success:function(data){
				console.info(data);
				$("#jygh").find("tbody").find("tr").remove();
				$(data["result"]).each(function(index,ele){
					var jyrq=new Date(ele["jyrq"]);
					var jyqx=new Date(ele["jyqx"]);
					$("#jygh").find("table").append("<tr  class='hand' >"+
											"<td  >"+ele["dwbm"]+"</td>"+
											"<td>"+ele["jyr"]+"</td>"+
											"<td>"+ele["bt"]+"</td>"+
											"<td>"+jyrq.Format("yyyy-MM-dd")+"</td>"+
											"<td>"+jyqx.Format("yyyy-MM-dd")+"</td>"+
											"<td><button  id="+ele["jyid"]+" value="+ele["nbxh"]+" class='ghbtn btn btn-primary'>归还</button></td>"+
										"</tr>");
				});
			},
			error:function(data){
				
			}
		});
	});
	/**
	 * 归还档案按钮监听
	 */
	$("#ghtable").on("click",".ghbtn",function(){
		var jyid=$(this).attr('id');
		var nbxh=$(this).val();
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Jyjl/sp",
			data:{jyid:jyid,ty:"1",nbxh:nbxh,status:0},
			success:function(data){
				if(data["result"]){
					toast.success("归还档案成功", "温馨提示");
					$("#"+jyid).parent().parent().remove();
				}
			},
			error:function(data){
				toast.error("归还出错，请刷新", "温馨提示");
			}
		});
	});
	
	$("#guidang").on("click",function(){
		var data=window.localStorage.getItem("guidang");
		var dangan=JSON.parse(data);
		var flh=$("#flh").val();
		var js=$("#jh").val().trim();
		var jnmlqx=$("#jnmlqx").val();
		var inmlqx=$("#inmlqx").val();
		var status=$("#status").val();
		var bgqx=$("#bgqx").val();
		var uploadType=$("#yxlj").attr("type");
		var moveType=0;
		var localFilePath="";
		if(uploadType=="file"){
			moveType=1;
			localFilePath=$("#serverFilePath").text();
		}else{
			moveType=2;
		}
		if(isNumber(js)||js==""||js==undefined){
			toast.error("件数不能为空", "温馨提示");
			hideLoader();
			return false;
		}
		showLoader();
	    $.ajax({
	    	type:"post",
	    	data:{vrecid:dangan["vrecid"],vlwbh:dangan["vlwbh"],vlwbt:dangan["vlwbt"],
	    		vlastdate:dangan["vlastdate"],vswbh:dangan["vswbh"],vlwdw:dangan["vlwdw"],
	    		vwjnr:dangan["vwjnr"],vtype:dangan["vtype"],nd:dangan["nd"],lj:dangan["lj"],
	    		dj:dangan["dj"],serverxh:dangan["serverxh"],bgqx:bgqx,
	    		flh:flh,js:js,jnmlqx:jnmlqx,inmlqx:inmlqx,moveType:moveType,filePath:localFilePath},
	    	url:"/dangan/webService/show/DaQyajb/guidang",
	    	success:function(data){
	    		hideLoader();
	    		if(data["success"]){
	    			toast.success("归档成功", "温馨提示");
	    			$(":input").each(function(){
	    				if($(this).attr("id")=='flh'){
	    					
	    				}else{
	    					$(this).val("");
	    				}
	    			});
	    		}else{
	    			toast.error("归档失败"+data["message"], "温馨提示");
	    			$(":input").each(function(){
	    				if($(this).attr("id")=='flh'){
	    					
	    				}else{
	    					$(this).val("");
	    				}
	    			});
	    		}
	    	},
	    	error:function(data){
	    		toast.error(date["message"], "温馨提示");
	    	}
	    	
	    });
	});
	//PhotoNum，用来统计现在添加的照片数量，以及组成元素的id
	window.localStorage.setItem("PhotoNum",1);
	$("#addPhoto").on("click",function(){
		var index=parseInt(window.localStorage.getItem("PhotoNum"));
		window.localStorage.setItem("PhotoNum",index+1);
		var string="<div class='row border_t photo'>"+
					"	<div class='col-md-7' style='padding: 5px;'>"+
					"		<div class='row'>"+
					"			<div class='col-md-4'>"+
					"				<div class='form-group ' >"+
					"					<label for='zph'>照片号</label> <input"+
					"						type='number' name='zpList["+index+"].zph' class='form-control' id='zph'  placeholder='摄影者'>"+
					"				</div>"+
					"			</div>"+
					"			<div class='col-md-8' style='margin-left: 0px;'>"+
					"				<div class=\"form-group \" >"+
					"					<label for=\"file\">照片</label> <input"+
					"						type=\"file\" class=\"form-control\" name=\"file\" id=\""+index+"\" placeholder=\"选择照片\">"+
					"				</div>"+
					"			</div>"+
					"		</div>"+
					"		<div class=\"row addPhoto\">"+
					"			<div class=\"col-md-12\">"+
					"				<div class=\"form-group \" >"+
					"				<label for=\"wzsm\">文字说明</label> <input"+
					"					type=\"text\" class=\"form-control\" name='zpList["+index+"].wzsm' id=\"wzsm\""+
					"					>"+
					"			</div>"+
					"			</div>"+
					"		</div>"+
					"	</div>"+
					"	<div class=\"col-md-5\" style=\" padding:10px 0px 0px 30px \">" +
					"		<img id=\"img"+index+"\" width=\"120\" height=\"120\" />" +
					"       <button class=\"btn btn-danger deletePhoto \" style=\"position: absolute;bottom: 0px;margin-left: 20px;\">删除</button>"+
					"   </div>"+
					"</div>";
		$(".photos").append(string);
	});
	//图片的上传
	$(".upload_btn").on("click",function(){
		
		$(this).attr("disabled","disabled");
		$("#photoForm").submit();
		window.localStorage.setItem("PhotoNum", 1);
	});
	//绑定图片预览的事件
	$("#photoForm").on("change",":file",function(){
		var index=parseInt($(this).attr("id"));
		var id="#img"+index;
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$(id).attr("src", objUrl) ;
		}
	});
	
	$("#photoForm").on("click",".btn-danger",function(){
		$(this).parent().parent().remove();
	});
	//照片归档的时候，已经选择的照片主体数量，点击归档后就重置为0
	window.localStorage.setItem("guidangPhotoNum",1);
	//照片归档时的选择事件,选择要归档的图片主题
	$(".gdPhoto").on("click",function(){
		var num=parseInt(window.localStorage.getItem("guidangPhotoNum"));
		if($(this).hasClass("photoSelected")){
			$(this).removeClass("photoSelected");
			$(this).css("background","#fff");
			var id="#"+$(this).attr('id');
			$('table').find(id).remove();
			var count=1;
			$('table').find(" td:even").each(function(index,ele){
				$(this).text(count);
				count++;
			});
			window.localStorage.setItem("guidangPhotoNum", num-1);
		}else{
			$(this).addClass("photoSelected");
			$(this).css("background","#3198F1");
			var id=$(this).attr('id');
			var tm=$(this).find('.tm').text();
			
			var tr="<tr id="+id+" >"+
					"	<td>"+num+"</td>"+
					"	<td>"+tm+"</td>"+
					"</tr>";
			$('#candidate').find('tbody').append(tr);
			window.localStorage.setItem("guidangPhotoNum", num+1);
		}
	});
	$(".btn_zpGuidang").on("click",function(){
		$(this).attr("disabled","disabled");
		var topics=new Array();
		var ajh=$("#ajh").val().trim();
		var hh=$("#hh").val().trim();
		var nd=$("#nd").val().trim();
		if(ajh==undefined||ajh==""){
			toast.error("请填写案卷号", "温馨提示");
			$(this).removeAttr("disabled");
			return false;
		}
		
		$("#candidate tr").each(function(index,ele){
			topics[index-1]=parseInt($(this).attr("id"));
		});
		if(topics.length<1){
			$(this).removeAttr("disabled");
			toast.error("选择要归档的照片组", "温馨提示");
			return false;
		}
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/dmtAjh/guiDang",
			traditional:true,
			data:{topicIds:topics,nd:nd,ajh:ajh,hh:hh},
			success:function(data){
				if(data["success"]){
					toast.success("照片归档成功", "温馨提示");
					parent.reloadFrame("query");
				}
			},
			error:function(data){
				toast.error("归还出错，请刷新", "温馨提示");
			}
		});
	});
	
	$(".btn_print_ml").on("click",function(){
		event.stopPropagation();
		var height=$(window).height();
		var width=$(window).width();
		var pdf=$("#printModal");
		pdf.find(".modal-body").css({
			height:height-50
		});
		pdf.find(".modal-dialog").css({
			width:width-100,
			height:height,
			margin:0,
			left:50
		});
		pdf.modal('show').css({
			 width: width,
             height:height
		});
		var ajh=$(this).attr("id");
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DmtZpTopic/getAjMl",
			data:{ajh:ajh},
			success:function(data){
				if(data["success"]){
					var counts=1;
					var counte=0;
					$("#printModal tbody tr").remove();
					$(data["list"]).each(function(index,ele){
						var time=Date.parse(ele["syrq"]);
						var date=new Date(parseInt(time)).Format("yyyy-MM-dd");
						var xh=index+1;
						if(xh!=1){
							counts=counte+1;
						}
						counte=counte+parseInt(ele["count"]);
						var topic="<tr>"+
									  "<td>"+xh+"</td>"+
									  "<td>"+ele["tm"]+"</td>"+
									  "<td>"+date+"</td>"+
									  "<td>"+counts+"—"+counte+"</td>"+
								  "</tr>";
						$("#printModal tbody").append(topic);
					});
				}
			},
			error:function(data){
				
			}
		});
	});
	$(".btn_print_sm").on("click",function(){
		event.stopPropagation();
		var height=$(window).height();
		var width=$(window).width();
		var pdf=$("#printSmModal");
		pdf.find(".modal-body").css({
			height:height-50
		});
		pdf.find(".modal-dialog").css({
			width:width-100,
			height:height,
			margin:0,
			left:50
		});
		pdf.modal('show').css({
			 width: width,
             height:height
		});
		var ajh=$(this).attr("id");
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/DmtZpTopic/getAjMl",
			data:{ajh:ajh},
			success:function(data){
				if(data["success"]){
					var counts=1;
					var counte=0;
					$("#printSmModal tbody tr").remove();
					$(data["list"]).each(function(index,ele){
						var xh=index+1;
						if(xh!=1){
							counts=counte+1;
						}
						counte=counte+parseInt(ele["count"]);
						var smlen=ele["sm"].length;
						var rowCount=1;
						if(smlen>32){
							if(smlen%32==0){
								rowCount=parseInt(smlen/32);
							}else{
								rowCount=parseInt(smlen/32)+1;
							}
							
						}
						var topic="";
						for(var i=0;i<rowCount;i++){
							var start=i*32;
							var subSm=ele["sm"].substr(start,32);
							console.info(subSm);
							if(i==0){
								topic=topic+"<tr>"+
								  "<td>"+counts+"—"+counte+"号照片</td>"+
								  "<td>"+subSm+"</td>"+
							  "</tr>";
							}else{
								topic=topic+"<tr>"+
								  "<td></td>"+
								  "<td>"+subSm+"</td>"+
							  "</tr>";
							}
						}
						
						$("#printSmModal tbody").append(topic);
					});
				}
			},
			error:function(data){
				
			}
		});
	});
	
	$(".print").on("click",function(){
		var gcwz=parseInt(window.localStorage.getItem("gcwz"));
		var flh=window.localStorage.getItem("printFlh");
		var url="";
		switch (gcwz) {
		case 0://馆藏位置在市局
			url=$("#pdfIframe")[0].contentWindow.getPrintPdfUrl();
			console.info(url);
			window.open(url);
			break;
		case 1://馆藏位置在江北
			url=$("#pdfIframe")[0].contentWindow.getPrintPdfUrl();
			console.info(url);
			window.open(url);
			break;
		case 2:
			url=$("#pdfIframe")[0].contentWindow.getPrintPdfUrl();
			console.info(url);
			break;
		default:
			break;
		}
		
	});
	$(".search_log").on("click",function(){
		var username=$("#userName").val().trim();
		var ip=$("#ip").val().trim();
		var startDate=$("#startDate").val();
		var endDate=$("#endDate").val();
		if(startDate==null||startDate==""){
			startDate=new Date(2000,0,1);
		}else{
			startDate=new Date(startDate);
		}
		if(endDate==null||endDate==""){
			endDate=new Date(2100,0,1);
		}else{
			endDate=new Date(endDate);
		}
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/Log/query",
			data:{name:username,ip:ip,everyPage:10,currentPage:1,endDate:endDate,startDate:startDate},
			success:function(data){
				$("tbody tr").remove();
				$("#totalCount").text("");
				console.info(data);
				window.localStorage.setItem("page", JSON.stringify(data));
				$(data["result"]).each(function(i,ele){
					var str="<tr>"+
								"<td>"+ele["humanname"]+"</td>"+
								"<td>"+ele["ip"]+"</td>"+
								"<td>"+ele["description"]+"</td>"+
								"<td>"+string.dateFormat(ele["date"], "yyyy-MM-dd hh:mm:ss")+"</td>"+
						    "</tr>";
					$("tbody").append(str);
				});
				$("#totalCount").text("第"+data["currentPage"]+"页  | 共"+data["totalPage"]+" 页"+" 共"+data["totalCount"]+"条记录");
			},
			error:function(data){
				
			}
		});
	});
	
	$("#anjuanTable").on("click",".btn_edit",function(event){
		event.stopPropagation();
		var nbxh=$(this).attr("id");
		var height=$(window).height();
		var width=$(window).width();
		var pdf=$("#bjModal");
		var flh=parent.getFlh();
		var url=$(this).val()+"&daFlh="+flh;
		//这个用来告诉等会要打印的文件的馆藏位置在哪里，来区分确定获取pdfurl的方法
		$("#danganEditIframe").attr('src',"danganEdit.action?nbxh="+nbxh);
		//$("#jnmlModal").modal('hide');
		pdf.find(".modal-body").css({
			height:height-55
		});
		pdf.find(".modal-dialog").css({
			width:width,
			height:height,
			margin:0
		});
		pdf.modal('show').css({
			 width: width,
             height:height
		});
	});

	
});

function getObjectURL(file) {
	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}
/**
 * 显示进度条
 */
function showLoader(){
	var target=$("#loader");
	var show = target.css('display');
	//$('#test').css('display',show =='block'?'none':show);
	if(show=='none'){
		target.css('display','block');
	}
	target.append(spinner.el);
}

function hideLoader(){
	var target=$("#loader");
	target.hide();
}
function back(){
	window.history.go(-1);
}

function isNumber(number){
	return isNaN(parseInt(number));
}

function clearInput(id) {
	if (id == 0) {
		$(":input").each(function() {
			$(this).val("");
		});
	} else {
		$(id).each(function() {
			$(this).val("");
		});
	}
	$("#addXmModal select").each(function(){
		$(this).val(0);
	});
};
function mySubmit(flag){  
    return flag;  
} ;
function isGuidang(recid){
};

function getWindowHieght(){
	var height=$(window).height();
	return height;
}

function getWindowWidth(){
	var width=$(window).width();
	return width;
}

function getSessionValue(key){
	var editable=window.sessionStorage.getItem("edit");
	if(editable==null||typeof(editable)==undefined||editable==""){
		$.ajax({
			type:"post",
			url:"/dangan/webService/show/tcrole/getSessionValue",
			data:{key:key},
			success:function(data){
				console.info(data["data"]);
				if(typeof(data)!=undefined&&data!=null&&data!=""){
					window.sessionStorage.setItem("edit", data["data"]);
				}
			},
			error:function(data){}
		});
	}
}


